<?php
require_once $ubi['SERVER']['SERVER_ROOT'] . '/dao/dbConnection.php';
require_once $ubi['SERVER']['SERVER_ROOT'] . '/model/address.php';

class CoupleInvitationDao {
	private $_db;

	public function __construct() {
		$this->_db = new DbConnection();
	}

	public function addCoupleInvitation($coupleInvitation) {
		$query = sprintf("CALL sp_AddCoupleInvitation('%u', '%u', '%s', '%s')",
     		$coupleInvitation->getUserID(),
     		$coupleInvitation->getCoupleID(),
     		$coupleInvitation->getDeleteCode(),
     		$coupleInvitation->getMessage());

     	$result = $this->_db->executeQuery($query);
		
		if (!$result) {
		    echo 'Could not run query: ' . ' ' . $query . ' ' . mysql_error();
		    return 0;
		}
		
		return 1;		
	}	
	
	public function removeCoupleInvitation($userID, $deleteCode) {
		$query = sprintf("DELETE FROM couple_invitation WHERE UserId = '%d' and DeleteCode = '%s'", 
			$userID, $deleteCode);
		$result = $this->_db->executeQuery($query);

		if (!$result) {
		    echo 'Could not run query: ' . ' ' . $query . ' ' . mysql_error();
		    return 0;
		}
		
		return mysql_affected_rows($result);
	}
}	
?>